Add raw STS error code to MsalFailure metric#5961
Merged
Conversation
bgavrilMS
approved these changes
Apr 29, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new OpenTelemetry tag on the MsalFailure counter to surface the raw ESTS error_codes value from MsalServiceException.ErrorCodes, and updates unit tests to validate presence/absence of the tag.
Changes:
- Add
TelemetryConstants.RawStsErrorCodetag name and plumb arawStsErrorCodeargument through the OTel instrumentation interface/call sites. - Emit
RawStsErrorCodeonMsalFailureonly when a non-empty raw STS error code is available. - Add unit tests verifying the tag is included for
MsalServiceExceptionand not included forMsalClientException.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Microsoft.Identity.Test.Unit/TelemetryTests/OTelInstrumentationTests.cs | Adds new tests for RawStsErrorCode tag behavior on MsalFailure. |
| src/client/Microsoft.Identity.Client/TelemetryCore/TelemetryConstants.cs | Introduces RawStsErrorCode telemetry tag constant. |
| src/client/Microsoft.Identity.Client/TelemetryCore/OpenTelemetry/NullOtelInstrumentation.cs | Extends failure logging signature to accept optional raw STS error code. |
| src/client/Microsoft.Identity.Client/TelemetryCore/OpenTelemetry/IOtelInstrumentation.cs | Extends interface to accept optional raw STS error code. |
| src/client/Microsoft.Identity.Client/Platforms/Features/OpenTelemetry/OtelInstrumentation.cs | Conditionally adds RawStsErrorCode tag to MsalFailure metric. |
| src/client/Microsoft.Identity.Client/Internal/Requests/SilentRequestHelper.cs | Passes first STS error code into failure metrics for proactive refresh failures. |
| src/client/Microsoft.Identity.Client/Internal/Requests/RequestBase.cs | Passes first STS error code into failure metrics for general request failures. |
…https://github.com/ssmelov/microsoft-authentication-library-for-dotnet into feature/add_sts_raw_error_code_to_msalfailure_metric
…https://github.com/AzureAD/microsoft-authentication-library-for-dotnet into feature/add_sts_raw_error_code_to_msalfailure_metric
neha-bhargava
approved these changes
Apr 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a RawStsErrorCode tag to the MsalFailure OpenTelemetry counter to surface the raw ESTS error code emitted by the identity provider (error_codes array).